package com.gamemost.managers;

import com.gamemost.layout.LayoutBase;
import com.gamemost.layout.LayoutViewReadBook;
import com.gamemost.templestay.MainActivity;

import android.view.View;

public class LayoutManager {
	private static LayoutManager instance;
	private MainActivity mParent;
	private View currentView = null;
	private LayoutBase currentLayout;
	public void setCurrentLayout(LayoutBase layout){
		this.currentLayout = layout;		
	}
	public LayoutBase getCurrentLayout(){
		return currentLayout;
	}
	public static LayoutManager getInstance(){
		if(instance == null){
			instance = new LayoutManager();
		}
		return instance;
	}
	public LayoutManager(){
		mParent = ResourcesManager.getInstance().ac;
	}
	
	public void addView(final View viewChild){
		mParent.runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				mParent.getMainFrameLayout().addView(viewChild);
				currentView = viewChild;
			}
		});
	}
	
	public View getCurrentView(){
		return currentView;
	}
	
	public void removeView(final View view){
		if(view != null){
			mParent.runOnUiThread(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					mParent.getMainFrameLayout().removeView(view);
				}				
			});
			int count = mParent.getMainFrameLayout().getChildCount();
			if(count > 1){
				currentView = mParent.getMainFrameLayout().getChildAt(count-1);
			}else{
				currentView = null;
			}
		}
	}
}
